package com.fhz.day007;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;

import com.fhz.day007.adapter.MyAdapter;
import com.fhz.day007.fragment.OneFragment;
import com.fhz.day007.fragment.TwoFragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private TabLayout tab;
    private ViewPager vp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tab = (TabLayout) findViewById(R.id.tab);
        vp = (ViewPager) findViewById(R.id.vp);

        //创建2个集合,1个f,1个t
        List<Fragment> fragmentList  = new ArrayList<>();
        fragmentList.add(OneFragment.newInstance("1","2"));
        fragmentList.add(new TwoFragment());
        fragmentList.add(new TwoFragment());
        fragmentList.add(new TwoFragment());
        fragmentList.add(new TwoFragment());
        fragmentList.add(new TwoFragment());
        fragmentList.add(new TwoFragment());
        fragmentList.add(new TwoFragment());
        fragmentList.add(new TwoFragment());

        //大小相等
        List<String> stringList = new ArrayList<>();
        stringList.add("首页");
        stringList.add("列表");
        stringList.add("列表");
        stringList.add("列表");
        stringList.add("列表");
        stringList.add("列表");
        stringList.add("列表");
        stringList.add("列表");
        stringList.add("列表");

        MyAdapter myAdapter = new MyAdapter(getSupportFragmentManager(), fragmentList, stringList);

        vp.setAdapter(myAdapter);

        tab.setupWithViewPager(vp);

    }
}